#include<bits/stdc++.h>
using namespace std;
int tnumber=0;int n;
struct node{
    int score;
    char c;
}a[200005];
int vis[200005]={0};
void dfs(int step,int total){
    if(step==n){
        tnumber=max(tnumber,total);
        return;
    }
    if(step>=1){
        bool k=true;
        for(int i=step-1;i>=0;i--){
            if(a[i].score==a[step].score){
                total+=a[step].score;
                a[step].c=a[i].c;
                k=false;
                break;
            }
        }
        if(k==true){
            if(a[step-1].c=='r'){
                a[step].c='b';
            }else{
                a[step].c='r';
            }
        }
        dfs(++step,total);
    }else{
        a[step].c='r';
        dfs(++step,total);
    }

}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    for(int i=1;i<=T;i++){
        cin>>n;
        for(int j=0;j<n;j++){
            cin>>a[j].score;
        }
        dfs(0,0);
        cout<<tnumber<<endl;
        tnumber=0;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
